#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int minSideJumps(vector<int> &obstacles)
    {
        const int obsValue = 500000;
        int lastTimes[3] = {1, 0, 1};
        for (int i = 1; i < obstacles.size(); i++)
        {
            int nt0, nt1, nt2;
            if (obstacles[i] == 0)
            {
                nt0 = std::min(lastTimes[0], std::min(lastTimes[1], lastTimes[2]) + 1);
                nt1 = std::min(lastTimes[1], std::min(lastTimes[0], lastTimes[2]) + 1);
                nt2 = std::min(lastTimes[2], std::min(lastTimes[0], lastTimes[1]) + 1);
            }
            else
            {
                if (obstacles[i] == 1)
                    nt0 = obsValue;
                else if (obstacles[i] == 2)
                    nt0 = std::min(lastTimes[0], lastTimes[2] + 1);
                else // 3
                    nt0 = std::min(lastTimes[0], lastTimes[1] + 1);

                if (obstacles[i] == 2)
                    nt1 = obsValue;
                else if (obstacles[i] == 1)
                    nt1 = std::min(lastTimes[2] + 1, lastTimes[1]);
                else
                    nt1 = std::min(lastTimes[0] + 1, lastTimes[1]);

                if (obstacles[i] == 3)
                    nt2 = obsValue;
                else if (obstacles[i] == 2)
                    nt2 = std::min(lastTimes[0] + 1, lastTimes[2]);
                else // 1
                    nt2 = std::min(lastTimes[1] + 1, lastTimes[2]);
            }

            lastTimes[0] = nt0;
            lastTimes[1] = nt1;
            lastTimes[2] = nt2;
            std::cout << i << '\t' << lastTimes[0] << "\t" << lastTimes[1] << "\t" << lastTimes[2] << std::endl;
        }
        return std::min(std::min(lastTimes[0], lastTimes[1]), lastTimes[2]);
    }
};

int main()
{
    cout << "Code1824" << endl;
    Solution s;
    std::vector<int> obstacles = {0, 2, 2, 1, 0, 3, 0, 3, 0, 1, 3, 1, 1, 0, 1, 3, 1, 1, 1, 0, 2, 0, 0, 3, 3, 0, 3, 2, 2, 0, 0, 3, 3, 3, 0, 0, 2, 0, 0, 3, 3, 0, 3, 3, 0, 0, 3, 1, 0, 1, 0, 2, 3, 1, 1, 0, 3, 3, 0, 3, 1, 3, 0, 2, 2, 0, 1, 3, 0, 1, 0, 3, 0, 1, 3, 1, 2, 2, 0, 0, 3, 0, 1, 3, 2, 3, 2, 1, 0, 3, 2, 2, 0, 3, 3, 0, 3, 0, 0, 1, 0};
    cout << s.minSideJumps(obstacles) << endl;
    return 0;
}